import requests
from common.get_header_tools import get_header


class IhrmEmpApi:
    # 添加员工
    def add_emp(self,req_header,req_body):
        resp = requests.post(url="http://ihrm2-test.itheima.net/api/sys/user",
                             headers=req_header,json=req_body)
        return resp

    # 查询员工
    def query_emp(self,emp_id,req_header):
        resp = requests.get(url="http://ihrm2-test.itheima.net/api/sys/user/"+ emp_id,
                            headers=req_header)
        return resp

    # 修改员工
    def update_emp(self,emp_id,req_header,req_body):
        resp = requests.put(url="http://ihrm2-test.itheima.net/api/sys/user/"+ emp_id,
                            headers=req_header,json=req_body)
        return resp
    # 删除员工
    def delete_emp(self,emp_id,req_header):
        resp = requests.delete(url="http://ihrm2-test.itheima.net/api/sys/user/"+ emp_id,
                               headers=req_header)
        return resp

if __name__ == '__main__':
    # 创建实例
    ihrm = IhrmEmpApi()
    req_header = get_header()
    req_body = {
        "username":"tom91",
        "mobile":"15800002211",
        "workNumber":"09"}
    resp = ihrm.add_emp(req_header,req_body)
    print("添加员工:",resp.json())

    # 查询员工
    emp_id = "1609900030074826752"
    req_header = get_header()
    resp = ihrm.query_emp(emp_id,req_header)
    print("查询员工：",resp.json())

    # 修改员工
    emp_id ="1609901061982662656"
    req_header = get_header()
    req_body = {"username":"jack888"}
    resp = ihrm.update_emp(emp_id,req_header,req_body)
    print("修改员工：",resp.json())

    # 删除员工
    emp_id="1609901942316740608"
    req_header= get_header()
    resp = ihrm.delete_emp(emp_id,req_header)
    print("删除员工：",resp.json())